package tools.lombok;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import java.util.Set;

@SupportedSourceVersion(SourceVersion.RELEASE_8)
//@SupportedAnnotationTypes(value = {"tools.lombok.MyAnnotation"})
public class MyAnnotationProcessor extends AbstractProcessor {

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){
        System.out.println("log in AbstractProcessor.process start");

        System.out.println("Log in AnnotationProcessor.process");
        for (TypeElement typeElement : annotations) {
            System.out.println(typeElement);
        }
        System.out.println(roundEnv);

        for(Element elem : roundEnv.getElementsAnnotatedWith(MyAnnotation.class)) {
            MyAnnotation annotation = elem.getAnnotation(MyAnnotation.class);
            String message ="annotation found in "+ elem.getSimpleName()
                    +" with  "+ annotation.value();
            //addToString(elem);
            System.out.println(message);
            processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message);
        }
        System.out.println("log in AbstractProcessor.process end");
        return true;// no further processing of this annotation type
    }
}
